package com.twp.imtest;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import io.rong.imkit.RongIM;
import io.rong.imlib.model.Conversation;

public class FragmentPageTest extends Fragment {

    private static FragmentPageTest mInstance;
    private String friendId;

    public static FragmentPageTest getInstance(String friendId) {
        if (mInstance == null) {
            mInstance = new FragmentPageTest();
            Bundle bundle = new Bundle();
            bundle.putString("fid", friendId);
            mInstance.setArguments(bundle);
        }
        return mInstance;
    }

    @Override
    public void setArguments(Bundle args) {
        super.setArguments(args);
        friendId = args.getString("fid");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Button textView = new Button(getActivity());
        textView.setText("和朋友" + friendId + "聊天");
        textView.setTextColor(Color.BLUE);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RongIM.getInstance().startPrivateChat(getActivity(), friendId, new UserInfoProvider().getUserInfo(friendId).getName());
            }
        });
        return textView;

    }
}
